package com.lx.springboot.dao;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.lx.springboot.pojo.Student;

@Repository
public class StuDao {
	@Autowired
	private JdbcTemplate jdbctemplate;
	
	public void createTable(){
		DataSource dataSource = jdbctemplate.getDataSource();
		String sql = "create  table if not EXISTS stus  (id int primary key auto_increment,name varchar(20),age int ,sex varchar(3),note varchar(255))";
		jdbctemplate.execute(sql);
	}
	
	public void save(Student s){
		String sql = "insert into stus (name,age,sex,note) values(?,?,?,?)";
		jdbctemplate.update(sql,s.getName(),s.getAge(),s.getSex(),s.getNote());
	}
}
